package net.cyl.strategy;

import org.apache.shardingsphere.api.sharding.standard.PreciseShardingAlgorithm;
import org.apache.shardingsphere.api.sharding.standard.PreciseShardingValue;

import java.util.Collection;

public class CustomTablePreciseShardingAlgorithm implements PreciseShardingAlgorithm<Comparable<?>> {
    @Override
    public String doSharding(Collection<String> collection, PreciseShardingValue<Comparable<?>> preciseShardingValue) {
        String tableName = collection.iterator().next();
        String value = preciseShardingValue.getValue().toString();
        String codeSuffix = value.substring(value.length() - 1);
        return tableName + "_" + codeSuffix;
    }
}
